package com.ds.infrastructure.audit.consumer.service;

import com.ds.infrastructure.audit.common.entity.Result;
import com.ds.infrastructure.audit.producer.api.service.WeatherApi;
import com.ds.infrastructure.audit.producer.api.vo.WeatherVO;
import com.ds.infrastructure.audit.road.api.service.RoadApi;
import com.ds.infrastructure.audit.road.api.vo.RoadVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作用：
 *
 * @author WeiShaoying
 */
@Service
@Slf4j
public class ConsumerService {

    @Autowired
    private WeatherApi weatherFeign;

    @Autowired
    private RoadApi roadApi;


    public String queryTodayWeather() {
        Result<WeatherVO> result = weatherFeign.queryTodayWeather();
        WeatherVO data = result.getData();
        return data.toString();
    }

    public String queryWeekWeather() {
        Result<List<WeatherVO>> listResult = weatherFeign.queryWeekWeather();
        WeatherVO data = listResult.getData().get(0);
        log.info("data={}", data);
        return listResult.toString();
    }

    public String queryRoadState() {
        Result<RoadVO> result = roadApi.queryRoadState();
        RoadVO roadVO = result.getData();
        log.info("roadVO={}", roadVO);
        return roadVO.toString();
    }

    public String queryBoth() {
        Result<RoadVO> result = roadApi.queryRoadState();
        RoadVO roadVO = result.getData();
        Result<WeatherVO> weatherResult = weatherFeign.queryTodayWeather();
        WeatherVO weatherVO = weatherResult.getData();
        return roadVO.toString() + "\n" + weatherVO.toString();
    }

}
